package net
{
	import flash3.net.ByteArrayPlus;
	import flash3.net.MsgPacket;
	
	import model.*;
	
	import vo.*;
	
	public class TableGroup extends MessageGroup
	{
		//房间状态数据包
		public static const MDM_GR_STATUS:uint					=	204									//状态信息
		public static const SUB_GR_TABLE_INFO:uint				=	100									//桌子信息
		public static const SUB_GR_TABLE_STATUS:uint				=	101									//桌子状态
		public static const SUB_GR_TABLE_INFO_REQ:uint			=	1									//桌子信息
			
		public static const IPC_MAIN_CONCTROL:uint				=4								//控制信息
		public static const IPC_SUB_START_FINISH:uint				=1								//启动完成
		public static const IPC_SUB_CLOSE_FRAME:uint				=2								//关闭框架
		public static const IPC_SUB_JOIN_IN_GAME:uint				=3								//加入游戏
			
		override public function defMessage():void
		{
			addMessage(new MessageDef(MDM_GR_STATUS, SUB_GR_TABLE_INFO, "桌子信息", onTableInfo));
			addMessage(new MessageDef(MDM_GR_STATUS, SUB_GR_TABLE_STATUS, "桌子状态", onTableStatus));
			addMessage(new MessageDef(MDM_GR_STATUS, SUB_GR_TABLE_INFO_REQ, "桌子信息", onTableInfoRequest));
			
			addMessage(new MessageDef(IPC_MAIN_CONCTROL, IPC_SUB_START_FINISH, "启动完成", onStartFinish));
			addMessage(new MessageDef(IPC_MAIN_CONCTROL, IPC_SUB_CLOSE_FRAME, "关闭框架", onCloseFrameRequest));
			addMessage(new MessageDef(IPC_MAIN_CONCTROL, IPC_SUB_JOIN_IN_GAME, "加入游戏", onJoinInGame));
		}
		
		public function onStartFinish(packet:MsgPacket):void
		{
			
		}
		public function onCloseFrameRequest(packet:MsgPacket):void
		{
			
		}
		public function onJoinInGame(packet:MsgPacket):void
		{
			
		}
		
		public function onTableInfo(packet:MsgPacket):void
		{
			var bap:ByteArrayPlus = packet._data;
			var wTableCount:uint = bap.readShort();
			var wTableIndex:uint = bap.readShort();
			if(wTableIndex == 0)
				TableStatusModel.i.clear();
			var wSiteID:int = MeInfoModel.i.serverInfo.wSiteID;
			for (var i:uint = 0; i < wTableCount; i++)
			{
				var tableInfo:TableInfo = new TableInfo();
				tableInfo.wSiteID = wSiteID;
				tableInfo.wTableID = i;
				tableInfo.bTableLock = bap.readByte();
				tableInfo.bPlayStatus = bap.readByte();
				TableStatusModel.i.add(i, tableInfo);
			}
		}
		public function onTableStatus(packet:MsgPacket):void
		{
			var bap:ByteArrayPlus = packet._data;
			
			var siteID:uint = bap.readShort();
			var tableID:uint = bap.readShort();
			var tableInfo:TableInfo = TableStatusModel.i.value(tableID);
			if(!tableInfo) return;
			tableInfo.wSiteID = siteID;
			tableInfo.bTableLock = bap.readByte();
			tableInfo.bPlayStatus = bap.readByte();
		}
		public function onTableInfoRequest(packet:MsgPacket):void
		{
			var bap:ByteArrayPlus = packet._data;
			var tableRequest:TableRequest = packet._parm as TableRequest;
			bap.writeShort(tableRequest.wSiteID);
			bap.writeShort(tableRequest.wTableID);
		}
	}
}